/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.plian.system.service.fr.bank.impl;

import com.plian.Tools.*;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.dao.sys.orgzation.OrgzationDao;
import com.plian.system.dto.fr.bank.BankCurrentHistoryDTO;
import com.plian.system.entity.fr.bank.BankCurrentHistory;
import com.plian.system.entity.fr.enterprise.Enterprise;
import com.plian.system.mapper.fr.bank.BankAccountInfoMapper;
import com.plian.system.mapper.fr.bank.BankCurrentHistoryMapper;
import com.plian.system.mapper.fr.bank.BankDepositMapper;
import com.plian.system.mapper.fr.monthRatio.OrganzationMonthRatioMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.properties.GzwProperties;
import com.plian.system.service.fr.bank.IBankCurrentHistoryService;
import com.plian.system.service.fr.enterprise.IEnterpriseService;
import com.plian.system.service.fr.organzationmonthratio.OrganzationMonthRatioService;
import com.plian.system.service.pm.property.IPropertyBasicsService;
import com.plian.system.service.sys.orgzation.IOrgService;
import com.plian.system.service.sys.orgzation.OrgzationService;
import com.plian.system.service.zzd.bank.IReportAccInfoService;
import com.plian.system.service.zzd.bank.IReportBalanceService;
import com.plian.system.vo.fr.bank.DepositStatisticsVO;
import com.plian.system.vo.fr.bank.OtherBankVO;
import com.plian.system.vo.report.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toMap;

/**
 * 服务实现类
 *
 * @author
 * @since 2019-09-27
 */
@Slf4j
@Service
@AllArgsConstructor
public class BankCurrentHistoryServiceImpl extends BaseServiceImpl<BankCurrentHistoryMapper, BankCurrentHistory> implements IBankCurrentHistoryService {

    private BankCurrentHistoryMapper bankCurrentHistoryMapper;

    private BankDepositMapper bankDepositMapper;

    private BankAccountInfoMapper bankAccountInfoMapper;

    private OrgzationDao orgzationDao;

    private OrgzationService orgzationService;

    private OrganzationMonthRatioService organzationMonthRatioService;

    private GzwProperties gzwProperties;

    private IEnterpriseService enterpriseService;

    private OrganzationMonthRatioMapper monthRatioMapper;

    private IOrgService orgService;

    private IPropertyBasicsService propertyBasicsService;

    private IReportAccInfoService accInfoService;

    private IReportBalanceService balanceService;

//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public boolean saveOrUpdate(BankCurrentHistory bankCurrentHistory) {
//        return super.saveOrUpdate(bankCurrentHistory);
//    }
//
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public boolean deleteLogic(List<Long> ids) {
//        for (Long id : ids) {
//            BankCurrentHistory bankCurrentHistory = getById(id);
//            if (bankCurrentHistory == null) {
//                return false;
//            }
//        }
//        return super.deleteLogic(ids);
//    }
//
//    /**
//     * 存款余额表格统计
//     *
//     * @param bankCurrentHistoryDTO
//     * @return
//     */
//    @Override
//    public ReportReturnVO dStatistics(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
//        List<DepositStatisticsVO> depositStatisticsVOList = generalList(bankCurrentHistoryDTO, 5);
//        DepositStatisticsVO total = total(depositStatisticsVOList);
//        List<OtherBankVO> bankTotal = total.getOthers();
//
//        ReportReturnVO reportReturnVO = new ReportReturnVO();
//        ReportVO reportVO = new ReportVO();
//
//        ArrayList<DepositStatisticsVO> data = new ArrayList<>();
//        ArrayList<HeaderVO> headerVOS = new ArrayList<>();
//
//
//        if (CollectionUtil.isNotEmpty(depositStatisticsVOList)) {
//            for (DepositStatisticsVO statisticsVO : depositStatisticsVOList) {
//                Map<String, OtherBankVO> othersMap = new HashMap<>();
//                DepositStatisticsVO depositStatisticsVO = new DepositStatisticsVO();
//                List<OtherBankVO> othersReturn = new ArrayList<>();
//                List<OtherBankVO> others = statisticsVO.getOthers();
//                BigDecimal othersB = new BigDecimal(0);
//                if (CollectionUtil.isNotEmpty(others)) {
//                    for (OtherBankVO other : others) {
//                        if (other.getBankCode() != null) {
//                            othersMap.put(other.getBankCode(), other);
//                        }
//                        othersB = BigDecimalUtil.add(othersB, other.getBalance());
//                    }
//                }
//                for (OtherBankVO otherBankVO : bankTotal) {
//                    OtherBankVO otherBank = othersMap.get(otherBankVO.getBankCode());
//                    if (otherBank != null) {
//                        othersReturn.add(otherBank);
//                    } else {
//                        if (otherBankVO.getBankCode() != null) {
//                            othersReturn.add(OtherBankVO.builder().bankCode(otherBankVO.getBankCode()).bankName(otherBankVO.getBankName()).balance(new BigDecimal(0)).build());
//                        }
//
//                    }
//                }
//                BigDecimal othersReturnB = new BigDecimal(0);
//                for (OtherBankVO otherBankVO : othersReturn) {
//                    othersReturnB = BigDecimalUtil.add(othersReturnB, otherBankVO.getBalance());
//                }
//                BigDecimal subtract = BigDecimalUtil.subtract(othersB, othersReturnB);
//                othersReturn.add(OtherBankVO.builder().bankCode(null).bankName("其他").balance(subtract).build());
//
//
//                depositStatisticsVO.setTopGroupId(statisticsVO.getTopGroupId());
//                depositStatisticsVO.setTopGroupName(statisticsVO.getTopGroupName());
//                depositStatisticsVO.setCompanyNumber(statisticsVO.getCompanyNumber() == null ? 0 : statisticsVO.getCompanyNumber());
//                depositStatisticsVO.setAccountNumber(statisticsVO.getAccountNumber() == null ? 0 : statisticsVO.getAccountNumber());
//                depositStatisticsVO.setBalance(statisticsVO.getBalance() == null ? new BigDecimal(0) : statisticsVO.getBalance());
//                depositStatisticsVO.setLastBalance(statisticsVO.getLastBalance() == null ? new BigDecimal(0) : statisticsVO.getLastBalance());
//                depositStatisticsVO.setMonthOnMonth(statisticsVO.getMonthOnMonth() == null ? new BigDecimal(0) : statisticsVO.getMonthOnMonth());
//                depositStatisticsVO.setOthers(othersReturn);
//                data.add(depositStatisticsVO);
//            }
//        }
//        if (CollectionUtil.isNotEmpty(bankTotal)) {
//            for (OtherBankVO otherBankVO : bankTotal) {
//                String bankName = otherBankVO.getBankName();
//                headerVOS.add(HeaderVO.builder().key("bankName").title(bankName).build());
//            }
//        }
//        reportVO.addHeader(HeaderVO.builder().key("topGroupName").title("集团名称").build())
//                .addHeader(HeaderVO.builder().key("companyNumber").title("公司数量").build())
//                .addHeader(HeaderVO.builder().key("accountNumber").title("账户数量").build())
//                .addHeader(HeaderVO.builder().key("balance").title("存款余额（万元）").build())
//                .addHeader(HeaderVO.builder().key("lastBalance").title("上期存款余额（万元）").build())
//                .addHeader(HeaderVO.builder().key("monthOnMonth").title("存款月度环比（%）").build())
//                .addHeader(HeaderVO.builder().key("others").title("其中").child(headerVOS).build());
//        data.add(total);
//        reportVO.setData(data);
//        reportReturnVO.setGrids(reportVO);
//        return reportReturnVO;
//    }

    /**
     * 存款余额分布
     *
     * @param bankCurrentHistoryDTO
     * @return
     */
    @Override
    public PieChartVO distribution(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
        ArrayList<PieValueVO> pieValueVOS = new ArrayList<>();
        ArrayList<String> bankData = new ArrayList<>();
        Map<String, OtherBankVO> endBankMap = new HashMap<>();

        List<DepositStatisticsVO> depositStatisticsVOList = generalList(bankCurrentHistoryDTO, 1);

        //银行合计
        DepositStatisticsVO end = total(depositStatisticsVOList);
        List<OtherBankVO> others = end.getOthers();
        if (CollectionUtil.isNotEmpty(others)) {
            for (OtherBankVO otherBanks : others) {
                if (endBankMap.containsKey(otherBanks.getBankName())) {
                    OtherBankVO endBankVO = endBankMap.get(otherBanks.getBankName());
                    endBankVO.setBalance(BigDecimalUtil.add(endBankVO.getBalance(), otherBanks.getBalance()));
                } else {
                    OtherBankVO endBankVO = new OtherBankVO();
                    endBankVO.setBankName(otherBanks.getBankName());
                    endBankVO.setBankCode(otherBanks.getBankCode());
                    endBankVO.setBalance(otherBanks.getBalance());
                    endBankMap.put(otherBanks.getBankName(), endBankVO);
                }
            }
        }
        List<OtherBankVO> otherBankVOList = new ArrayList<>(endBankMap.values());
        otherBankVOList = otherBankVOList.stream().filter(s -> s.getBankName() != null).sorted(Comparator.comparing(OtherBankVO::getBalance).reversed())
                .collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(otherBankVOList)) {
            for (OtherBankVO vo : otherBankVOList) {
                bankData.add(vo.getBankName());
                pieValueVOS.add(PieValueVO.builder().value(vo.getBalance()).name(vo.getBankName()).build());
            }
        }
        LegendVO legendVO = LegendVO.builder().data(bankData).build();
        PieChartVO pieChartVO = PieChartVO.builder().data(pieValueVOS).legend(legendVO).build();
        return pieChartVO;
    }

    /**
     * 存款余额占比
     *
     * @param bankCurrentHistoryDTO
     * @return
     */
    @Override
    public PieChartVO proportion(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
        ArrayList<String> topGroupNames = new ArrayList<>();
        ArrayList<PieValueVO> pieValueVOS = new ArrayList<>();
        List<DepositStatisticsVO> depositStatisticsVOList = generalList(bankCurrentHistoryDTO, 2);
        if (CollectionUtil.isNotEmpty(depositStatisticsVOList)) {
            getUnitName(depositStatisticsVOList);
            for (DepositStatisticsVO depositStatisticsVO : depositStatisticsVOList) {
                topGroupNames.add(depositStatisticsVO.getTopGroupName());
                PieValueVO pieValueVO = PieValueVO.builder().name(depositStatisticsVO.getTopGroupName()).value(depositStatisticsVO.getBalance()).build();
                pieValueVOS.add(pieValueVO);
            }
        }
        LegendVO legendVO = LegendVO.builder().data(topGroupNames).build();
        PieChartVO pieChartVO = PieChartVO.builder().data(pieValueVOS).legend(legendVO).build();
        return pieChartVO;
    }

    /**
     * @Author: Take-off
     * @Description: //TODO 获取集团简称
     * @Date: 9:39 AM 2022/8/18
     * @Param: [depositStatisticsVOList]
     * @return: void
     **/
    private void getUnitName(List<DepositStatisticsVO> depositStatisticsVOList){
        if (CollectionUtil.isNotEmpty(depositStatisticsVOList)){
            List<String> orgIds = depositStatisticsVOList.stream().map(DepositStatisticsVO::getTopGroupId).collect(Collectors.toList());
            PageData pageData = new PageData();
            pageData.put("orgIds",orgIds);
            //获取集团简称
            try {
                List<Enterprise> enterprises = enterpriseService.findByOrgIds(orgIds);
                for (DepositStatisticsVO depositStatisticsVO:depositStatisticsVOList){
                    List<Enterprise> enterpriseByOrg = enterprises.stream().filter(m -> m.getOrgId().equals(depositStatisticsVO.getTopGroupId())).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(enterpriseByOrg)){
                        String unitCheck = enterpriseByOrg.get(0).getUnitCheck();
                        depositStatisticsVO.setTopGroupName(unitCheck);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }

//    /**
//     * 开户情况统计
//     *
//     * @param bankCurrentHistoryDTO
//     * @return
//     */
//    @Override
//    public ChartsVO kStatistics(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
//        ArrayList<String> data = new ArrayList<>();
//        ArrayList<XAxisVO> xAxisVOS = new ArrayList<>();
//        ArrayList<String> company = new ArrayList<>();
//        ArrayList<Object> dataList1 = new ArrayList<>();
//        ArrayList<Object> dataList2 = new ArrayList<>();
//        ArrayList<Object> dataList3 = new ArrayList<>();
//        List<SeriesVO> series = new ArrayList<>();
//
//        List<DepositStatisticsVO> depositStatisticsVOList = generalList(bankCurrentHistoryDTO, 3);
//        if (CollectionUtil.isNotEmpty(depositStatisticsVOList)) {
//            getUnitName(depositStatisticsVOList);
//            for (DepositStatisticsVO depositStatisticsVO : depositStatisticsVOList) {
//                dataList1.add(depositStatisticsVO.getCompanyNumber());
//                dataList2.add(depositStatisticsVO.getAccountNumber());
//                dataList3.add(depositStatisticsVO.getBalance());
//                company.add(depositStatisticsVO.getTopGroupName());
//            }
//        }
//
//        data.add("公司数量");
//        data.add("账户数量");
//        data.add("存款余额（万元）");
//        LegendVO legendVO = LegendVO.builder().data(data).build();
//
//        XAxisVO xAxisVO = XAxisVO.builder().data(company).build();
//        xAxisVOS.add(xAxisVO);
//
//        SeriesVO seriesVO1 = SeriesVO.builder().data(dataList1).name("公司数量").type("bar").build();
//        SeriesVO seriesVO2 = SeriesVO.builder().data(dataList2).name("账户数量").type("bar").build();
//        SeriesVO seriesVO3 = SeriesVO.builder().data(dataList3).name("存款余额（万元）").type("line").yAxisIndex(1).build();
//        series.add(seriesVO1);
//        series.add(seriesVO2);
//        series.add(seriesVO3);
//
//        ChartsVO chartsVO = ChartsVO.builder().legend(legendVO).series(series).xAxis(xAxisVOS).build();
//        return chartsVO;
//    }
//
//    /**
//     * 存款月度环比
//     *
//     * @param bankCurrentHistoryDTO
//     * @return
//     */
//    @Override
//    public ChartsVO monthOnMonth(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
//        ArrayList<String> data = new ArrayList<>();
//        ArrayList<XAxisVO> xAxisVOS = new ArrayList<>();
//        ArrayList<String> company = new ArrayList<>();
//        ArrayList<Object> dataList1 = new ArrayList<>();
//        ArrayList<Object> dataList2 = new ArrayList<>();
//        ArrayList<Object> dataList3 = new ArrayList<>();
//        List<SeriesVO> series = new ArrayList<>();
//
//        BigDecimal balanceCount = new BigDecimal(0);
//        BigDecimal lastBalanceCount = new BigDecimal(0);
//        BigDecimal monthToMonthTotal = new BigDecimal(0);
//        List<DepositStatisticsVO> depositStatisticsVOList = generalList(bankCurrentHistoryDTO, 4);
//        if (CollectionUtil.isNotEmpty(depositStatisticsVOList)) {
//            getUnitName(depositStatisticsVOList);
//            for (DepositStatisticsVO depositStatisticsVO : depositStatisticsVOList) {
//                dataList1.add(depositStatisticsVO.getBalance());
//                dataList2.add(depositStatisticsVO.getLastBalance());
//                dataList3.add(depositStatisticsVO.getMonthOnMonth());
//                company.add(depositStatisticsVO.getTopGroupName());
//                //本月合计
//                balanceCount = BigDecimalUtil.add(balanceCount, depositStatisticsVO.getBalance());
//                //上月合计
//                lastBalanceCount = BigDecimalUtil.add(lastBalanceCount, depositStatisticsVO.getLastBalance());
//                //合计环比
//                monthToMonthTotal = BigDecimalUtil.divide(BigDecimalUtil.subtract(balanceCount, lastBalanceCount),
//                        lastBalanceCount, 2, BigDecimal.ROUND_HALF_UP, 100);
//                if (monthToMonthTotal == null) {
//                    monthToMonthTotal = new BigDecimal(0);
//                }
//            }
//        }
//
//        data.add("存款余额（万元）");
//        data.add("上期存款余额（万元）");
//        data.add("存款月度环比");
//        LegendVO legendVO = LegendVO.builder().data(data).build();
//
//        company.add("合计");
//        XAxisVO xAxisVO = XAxisVO.builder().data(company).build();
//        xAxisVOS.add(xAxisVO);
//
//        dataList1.add(balanceCount);
//        dataList2.add(lastBalanceCount);
//        dataList3.add(monthToMonthTotal);
//
//        SeriesVO seriesVO1 = SeriesVO.builder().data(dataList1).name("存款余额（万元）").type("bar").build();
//        SeriesVO seriesVO2 = SeriesVO.builder().data(dataList2).name("上期存款余额（万元）").type("bar").build();
//        SeriesVO seriesVO3 = SeriesVO.builder().data(dataList3).name("存款月度环比").type("line").yAxisIndex(1).build();
//        series.add(seriesVO1);
//        series.add(seriesVO2);
//        series.add(seriesVO3);
//
//        ChartsVO chartsVO = ChartsVO.builder().legend(legendVO).series(series).xAxis(xAxisVOS).build();
//        return chartsVO;
//    }
//
//    @Override
//    public ReportReturnVO structureStatistics(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
//        ReportVO reportVO = new ReportVO();
//        reportVO
//                .addHeader(HeaderVO.builder().key("topGroupName").title("集团名称").build())
//                .addHeader(HeaderVO.builder().key("companyNumber").title("公司数量").build())
//                .addHeader(HeaderVO.builder().key("balance").title("存款余额（万元）").build());
//
//        List<Integer> depositTypes = bankCurrentHistoryDTO.getDepositTypes();
//        if (CollectionUtil.isNotEmpty(depositTypes)) {
//            if (depositTypes.contains(1)) {
//                reportVO.addHeader(HeaderVO.builder().key("demandDeposits").title("活期存款").build());
//            }
//
//            if (depositTypes.contains(2)) {
//                reportVO.addHeader(HeaderVO.builder().key("timeDeposits").title("定期存款").build());
//            }
//
//            if (depositTypes.contains(7)) {
//                reportVO.addHeader(HeaderVO.builder().key("financeAmount").title("理财及投资").build());
//            }
//
//            if (depositTypes.contains(8)) {
//                reportVO.addHeader(HeaderVO.builder().key("structuredDeposits").title("结构性存款").build());
//            }
//        } else {
//            reportVO.addHeader(HeaderVO.builder().key("demandDeposits").title("活期存款").build())
//                    .addHeader(HeaderVO.builder().key("timeDeposits").title("定期存款").build())
//                    .addHeader(HeaderVO.builder().key("financeAmount").title("理财及投资").build())
//                    .addHeader(HeaderVO.builder().key("structuredDeposits").title("结构性存款").build());
//        }
//
//        List<DepositStatisticsVO> results = statistics(bankCurrentHistoryDTO);
//        if (CollectionUtil.isNotEmpty(results)) {
//            DepositStatisticsVO end = sum(results);
//            results.add(end);
//        }
//
//        ReportReturnVO reportReturnVO = new ReportReturnVO();
//        reportVO.setData(results);
//        reportReturnVO.setGrids(reportVO);
//        return reportReturnVO;
//    }
//
//    @Override
//    public PieChartVO structureDistribution(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
//        List<DepositStatisticsVO> results = statistics(bankCurrentHistoryDTO);
//        if (CollectionUtil.isNotEmpty(results)) {
//            DepositStatisticsVO end = sum(results);
//            List<String> data = new ArrayList<>();
//            List<PieValueVO> pieValueVOS = new ArrayList<>();
//            List<Integer> depositTypes = bankCurrentHistoryDTO.getDepositTypes();
//
//            if (CollectionUtil.isNotEmpty(depositTypes)) {
//                if (depositTypes.contains(1)) {
//                    data.add("活期存款");
//                    pieValueVOS.add(PieValueVO.builder().name("活期存款")
//                            .value(end.getDemandDeposits() != null ? end.getDemandDeposits() : new BigDecimal(0)).build());
//                }
//
//                if (depositTypes.contains(2)) {
//                    data.add("定期存款");
//                    pieValueVOS.add(PieValueVO.builder().name("定期存款")
//                            .value(end.getTimeDeposits() != null ? end.getTimeDeposits() : new BigDecimal(0)).build());
//                }
//
//                if (depositTypes.contains(7)) {
//                    data.add("理财及投资");
//                    pieValueVOS.add(PieValueVO.builder().name("理财及投资")
//                            .value(end.getFinanceAmount() != null ? end.getFinanceAmount() : new BigDecimal(0)).build());
//                }
//
//                if (depositTypes.contains(8)) {
//                    data.add("结构性存款");
//                    pieValueVOS.add(PieValueVO.builder().name("结构性存款")
//                            .value(end.getStructuredDeposits() != null ? end.getStructuredDeposits() : new BigDecimal(0)).build());
//                }
//            } else {
//                data.add("活期存款");
//                data.add("定期存款");
//                data.add("理财及投资");
//                data.add("结构性存款");
//                pieValueVOS.add(PieValueVO.builder().name("活期存款")
//                        .value(end.getDemandDeposits() != null ? end.getDemandDeposits() : new BigDecimal(0)).build());
//                pieValueVOS.add(PieValueVO.builder().name("定期存款")
//                        .value(end.getTimeDeposits() != null ? end.getTimeDeposits() : new BigDecimal(0)).build());
//                pieValueVOS.add(PieValueVO.builder().name("理财及投资")
//                        .value(end.getFinanceAmount() != null ? end.getFinanceAmount() : new BigDecimal(0)).build());
//                pieValueVOS.add(PieValueVO.builder().name("结构性存款")
//                        .value(end.getStructuredDeposits() != null ? end.getStructuredDeposits() : new BigDecimal(0)).build());
//            }
//
//            LegendVO legendVO = LegendVO.builder().data(data).build();
//            PieChartVO pieChartVO = PieChartVO.builder().legend(legendVO).data(pieValueVOS).build();
//            return pieChartVO;
//        }
//        return null;
//    }
//
//    @Override
//    public PieChartVO structureCompany(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
//        String date;
//        String month = bankCurrentHistoryDTO.getMonth();
//        String currentMonth = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_MONTH);
//        if (StringUtil.isBlank(month) || month.equals(currentMonth)) {
//            date = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATE);
//        } else {
//            date = DateUtil.format(DateUtil.minusDays(DateUtil.plusMonths(
//                    DateUtil.parse(month + "-01", DateUtil.PATTERN_DATE), 1), 1), DateUtil.PATTERN_DATE);
//        }
//        List<DepositStatisticsVO> results = bankDepositMapper.statisticsByTopId(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getDepositTypes());
//
//        if (CollectionUtil.isNotEmpty(results)) {
//            getUnitName(results);
//            List<String> data = new ArrayList<>();
//            List<PieValueVO> pieValueVOS = new ArrayList<>();
//            for (DepositStatisticsVO result : results) {
//                data.add(result.getTopGroupName());
//                pieValueVOS.add(PieValueVO.builder().name(result.getTopGroupName())
//                        .value(BigDecimalUtil.divide(result.getStructuredDeposits(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP))
//                        .build());
//            }
//            LegendVO legendVO = LegendVO.builder().data(data).build();
//            PieChartVO pieChartVO = PieChartVO.builder().legend(legendVO).data(pieValueVOS).build();
//            return pieChartVO;
//        }
//        return null;
//    }
//
//    private DepositStatisticsVO sum(List<DepositStatisticsVO> results) {
//        DepositStatisticsVO end = DepositStatisticsVO.builder().topGroupName("合计").build();
//        for (DepositStatisticsVO result : results) {
//            end.setCompanyNumber(BigDecimalUtil.integerAdd(end.getCompanyNumber(), result.getCompanyNumber()));
//            end.setBalance(BigDecimalUtil.add(end.getBalance(), result.getBalance()));
//            end.setDemandDeposits(BigDecimalUtil.add(end.getDemandDeposits(), result.getDemandDeposits()));
//            end.setTimeDeposits(BigDecimalUtil.add(end.getTimeDeposits(), result.getTimeDeposits()));
//            end.setFinanceAmount(BigDecimalUtil.add(end.getFinanceAmount(), result.getFinanceAmount()));
//            end.setStructuredDeposits(BigDecimalUtil.add(end.getStructuredDeposits(), result.getStructuredDeposits()));
//        }
//        return end;
//    }

    @Override
    public List<DepositStatisticsVO> statistics(BankCurrentHistoryDTO bankCurrentHistoryDTO) {
        boolean flag = true;
        int type;
        String date;
        String month = bankCurrentHistoryDTO.getMonth();
        String currentMonth = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_MONTH);
        if (StringUtil.isBlank(month) || month.equals(currentMonth)) {
            type = 1;
            date = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATE);
        } else {
            date = DateUtil.format(DateUtil.minusDays(DateUtil.plusMonths(
                    DateUtil.parse(month + "-01", DateUtil.PATTERN_DATE), 1), 1), DateUtil.PATTERN_DATE);
            type = 2;
        }

		// 公司数量统计
		List<DepositStatisticsVO> companyNumberList = new ArrayList<>();
		switch (type){
			case 1:
				companyNumberList = bankAccountInfoMapper.getCompanyNumber(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getDepositTypes());
				break;
			case 2:
				companyNumberList = bankCurrentHistoryMapper.getCompanyNumber(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getDepositTypes());
				break;
			default:
				break;
		}

        List<Integer> depositTypes = bankCurrentHistoryDTO.getDepositTypes();
        if (CollectionUtil.isNotEmpty(depositTypes)) {
            if (depositTypes.contains(1) && depositTypes.size() == 1) {
                // 只查询活期
                flag = false;
            }

            if (!depositTypes.contains(1)) {
                // 活期存款不查询
                type = 0;
            }
        }

        //活期存款统计
        List<DepositStatisticsVO> demandList = new ArrayList<>();
        switch (type) {
            case 1:
                demandList = bankAccountInfoMapper.statisticsByTopId(bankCurrentHistoryDTO.getTopGroupIds());
                break;
            case 2:
                demandList = bankCurrentHistoryMapper.statisticsByTopId(date, bankCurrentHistoryDTO.getTopGroupIds());
                break;
            default:
                break;
        }

        //定期等存款统计
        List<DepositStatisticsVO> list = new ArrayList<>();
        if (flag) {
            list = bankDepositMapper.statisticsByTopId(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getDepositTypes());
        }

        if (CollectionUtil.isNotEmpty(companyNumberList)) {
            Map<String, DepositStatisticsVO> demandMap = new HashMap<>();
            if (CollectionUtil.isNotEmpty(demandList)) {
                for (DepositStatisticsVO demandVO : demandList) {
                    demandMap.put(demandVO.getTopGroupId(), demandVO);
                }
            }
            Map<String, DepositStatisticsVO> map = new HashMap<>();
            if (CollectionUtil.isNotEmpty(list)) {
                for (DepositStatisticsVO vo : list) {
                    map.put(vo.getTopGroupId(), vo);
                }
            }

            for (DepositStatisticsVO result : companyNumberList) {
                if (demandMap.containsKey(result.getTopGroupId())) {
                    DepositStatisticsVO demandVO = demandMap.get(result.getTopGroupId());
                    result.setDemandDeposits(BigDecimalUtil.divide(demandVO.getDemandDeposits(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                    result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getDemandDeposits()));
                }

                if (map.containsKey(result.getTopGroupId())) {
                    DepositStatisticsVO vo = map.get(result.getTopGroupId());
                    if (CollectionUtil.isEmpty(depositTypes)) {
                        result.setTimeDeposits(BigDecimalUtil.divide(vo.getTimeDeposits(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                        result.setStructuredDeposits(BigDecimalUtil.divide(vo.getStructuredDeposits(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                        result.setFinanceAmount(BigDecimalUtil.divide(vo.getFinanceAmount(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                        result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getTimeDeposits()));
                        result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getStructuredDeposits()));
                        result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getFinanceAmount()));
                    } else {
                        if (depositTypes.contains(2)) {
                            result.setTimeDeposits(BigDecimalUtil.divide(vo.getTimeDeposits(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                            result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getTimeDeposits()));
                        }

                        if (depositTypes.contains(7)) {
                            result.setFinanceAmount(BigDecimalUtil.divide(vo.getFinanceAmount(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                            result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getFinanceAmount()));
                        }

                        if (depositTypes.contains(8)) {
                            result.setStructuredDeposits(BigDecimalUtil.divide(vo.getStructuredDeposits(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                            result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getStructuredDeposits()));
                        }
                    }
                }
            }
        }
        return companyNumberList;
    }

    private List<DepositStatisticsVO> sumByTopId(List<DepositStatisticsVO> demandList, List<DepositStatisticsVO> list, List<DepositStatisticsVO> companyNumberList) {
        if (CollectionUtil.isNotEmpty(companyNumberList)) {
            for (DepositStatisticsVO result : companyNumberList) {
                if (CollectionUtil.isNotEmpty(demandList)) {
                    for (DepositStatisticsVO depositStatisticsVO : demandList) {
                        if (result.getTopGroupId().equals(depositStatisticsVO.getTopGroupId())) {
                            List<OtherBankVO> others = depositStatisticsVO.getOthers();
                            if (CollectionUtil.isNotEmpty(others)) {
                                BigDecimal demandDeposits = others.stream().map(OtherBankVO::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
                                result.setDemandDeposits(BigDecimalUtil.divide(demandDeposits, new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                                result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getDemandDeposits()));
                            }
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(list)) {
                    for (DepositStatisticsVO depositStatisticsVO : list) {
                        if (result.getTopGroupId().equals(depositStatisticsVO.getTopGroupId())) {
                            List<OtherBankVO> others = depositStatisticsVO.getOthers();
                            if (CollectionUtil.isNotEmpty(others)) {
                                BigDecimal timeDeposits = others.stream().map(OtherBankVO::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
                                result.setTimeDeposits(BigDecimalUtil.divide(timeDeposits, new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                                result.setBalance(BigDecimalUtil.add(result.getBalance(), result.getTimeDeposits()));
                            }
                        }
                    }
                }
            }
        }
        return companyNumberList;
    }

    private List<DepositStatisticsVO> lastSumByTopId(List<DepositStatisticsVO> demandList, List<DepositStatisticsVO> list, List<DepositStatisticsVO> companyNumberList) {
        if (CollectionUtil.isNotEmpty(companyNumberList)) {
            for (DepositStatisticsVO result : companyNumberList) {
                if (CollectionUtil.isNotEmpty(demandList)) {
                    for (DepositStatisticsVO depositStatisticsVO : demandList) {
                        if (result.getTopGroupId().equals(depositStatisticsVO.getTopGroupId())) {
                            List<OtherBankVO> others = depositStatisticsVO.getOthers();
                            if (CollectionUtil.isNotEmpty(others)) {
                                BigDecimal demandDeposits = others.stream().map(OtherBankVO::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
                                result.setDemandDeposits(BigDecimalUtil.divide(demandDeposits, new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                                result.setLastBalance(BigDecimalUtil.add(result.getLastBalance(), result.getDemandDeposits()));
                            }
                        }
                    }
                }
                if (CollectionUtil.isNotEmpty(list)) {
                    for (DepositStatisticsVO depositStatisticsVO : list) {
                        if (result.getTopGroupId().equals(depositStatisticsVO.getTopGroupId())) {
                            List<OtherBankVO> others = depositStatisticsVO.getOthers();
                            if (CollectionUtil.isNotEmpty(others)) {
                                BigDecimal timeDeposits = others.stream().map(OtherBankVO::getBalance).reduce(BigDecimal.ZERO, BigDecimal::add);
                                result.setTimeDeposits(BigDecimalUtil.divide(timeDeposits, new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                                result.setLastBalance(BigDecimalUtil.add(result.getLastBalance(), result.getTimeDeposits()));
                            }
                        }
                    }
                }
            }
        }
        return companyNumberList;
    }

    private DepositStatisticsVO total(List<DepositStatisticsVO> results) {
        DepositStatisticsVO end = DepositStatisticsVO.builder().topGroupName("合计").build();

        List<OtherBankVO> bankVOS = new ArrayList<>();
        Map<String, BigDecimal> sorted = new HashMap<>();
        if (CollectionUtil.isNotEmpty(results)) {
            for (DepositStatisticsVO result : results) {
                List<OtherBankVO> otherBankVOS = result.getOthers();
                if(CollectionUtil.isNotEmpty(otherBankVOS)){
                    bankVOS.addAll(otherBankVOS);
                }
            }
            if (CollectionUtil.isNotEmpty(bankVOS)) {
                Map<String, BigDecimal> bankMap = bankVOS.stream().collect(Collectors.groupingBy(OtherBankVO::getBankCode,
                        Collectors.reducing(BigDecimal.ZERO, OtherBankVO::getBalance, BigDecimal::add)));
                //排序
                sorted = bankMap
                        .entrySet()
                        .stream()
                        .sorted(Collections.reverseOrder(comparingByValue()))
                        .collect(
                                toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2,
                                        LinkedHashMap::new));

            }
        }

        List<OtherBankVO> bankVOs = new ArrayList<>();
        List<OtherBankVO> endBankVOList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(sorted)) {
            Set<Map.Entry<String, BigDecimal>> entrySet = sorted.entrySet();
            for (Map.Entry<String, BigDecimal> stringBigDecimalEntry : entrySet) {
                OtherBankVO otherBankVO = new OtherBankVO();
                otherBankVO.setBankCode(stringBigDecimalEntry.getKey());
                otherBankVO.setBalance(stringBigDecimalEntry.getValue());
                bankVOs.add(otherBankVO);
            }
            BigDecimal count = new BigDecimal(0);
            String other = "其他";
            BigDecimal bankBalance = new BigDecimal(0);
            if (CollectionUtil.isNotEmpty(bankVOs)) {
                for (int i = 0; i < bankVOs.size(); i++) {
                    OtherBankVO otherBanks = new OtherBankVO();
                    if (i > 6) {
                        count = BigDecimalUtil.add(bankVOs.get(i).getBalance(), count);
                        if (i == bankVOs.size() - 1) {
                            otherBanks.setBankName(other);
                            otherBanks.setBalance(count);
                            endBankVOList.add(otherBanks);
                        }
                    } else {
                        OtherBankVO otherBankVO = bankVOs.get(i);
                        bankBalance = otherBankVO.getBalance();
                        otherBanks.setBankCode(otherBankVO.getBankCode());
                        for (OtherBankVO bankVO : bankVOS) {
                            if (bankVO.getBankCode().equals(otherBankVO.getBankCode())) {
                                otherBanks.setBankName(bankVO.getBankName());
                            }
                        }
                        otherBanks.setBalance(bankBalance);
                        endBankVOList.add(otherBanks);
                    }
                }
            }
        }
        if (CollectionUtil.isNotEmpty(results)) {
            for (DepositStatisticsVO result : results) {
                end.setCompanyNumber(BigDecimalUtil.integerAdd(end.getCompanyNumber(), result.getCompanyNumber()));
                end.setAccountNumber(BigDecimalUtil.integerAdd(end.getAccountNumber(), result.getAccountNumber()));
                end.setBalance(BigDecimalUtil.add(end.getBalance(), result.getBalance()));
                end.setLastBalance(BigDecimalUtil.add(end.getLastBalance(), result.getLastBalance()));
                end.setMonthOnMonth(BigDecimalUtil.divide(BigDecimalUtil.subtract(end.getBalance(), end.getLastBalance()),
                        end.getLastBalance(), 2, BigDecimal.ROUND_HALF_UP, 100));
                end.setOthers(endBankVOList);
            }
        }
        return end;
    }

    /**
     * 计算活期定期和
     *
     * @param depositList
     * @param timeList
     * @return
     */
    private List<DepositStatisticsVO> sumList(List<DepositStatisticsVO> depositList, List<DepositStatisticsVO> timeList) {
        List<DepositStatisticsVO> sumList = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(depositList) && CollectionUtil.isNotEmpty(timeList)) {
            for (DepositStatisticsVO depositVO : depositList) {
                for (DepositStatisticsVO timeVO : timeList) {
                    if (depositVO.getTopGroupId().equals(timeVO.getTopGroupId())) {
                        List<OtherBankVO> depositOthers = depositVO.getOthers();
                        depositOthers.addAll(timeVO.getOthers());
                        DepositStatisticsVO build = DepositStatisticsVO.builder().others(depositOthers).topGroupId(timeVO.getTopGroupId()).build();
                        sumList.add(build);
                    }
                }
            }
        }
        if (CollectionUtil.isNotEmpty(sumList)) {
            for (DepositStatisticsVO depositStatisticsVO : sumList) {
                List<OtherBankVO> others = depositStatisticsVO.getOthers();
                List<OtherBankVO> otherSum = new ArrayList<>();
                Set<String> bankSet = new HashSet<>();
                if (CollectionUtil.isNotEmpty(others)) {
                    for (OtherBankVO other : others) {
                        bankSet.add(other.getBankCode());
                    }
                }
                if (CollectionUtil.isNotEmpty(bankSet)) {
                    for (String code : bankSet) {
                        List<OtherBankVO> bank = new ArrayList<>();
                        for (OtherBankVO other : others) {
                            if (code.equals(other.getBankCode())) {
                                bank.add(other);
                            }
                            if (bank.size() > 1) {
                                BigDecimal money = new BigDecimal(0);
                                for (OtherBankVO otherBankVO : bank) {
                                    money = BigDecimalUtil.add(money, otherBankVO.getBalance());
                                }
                                OtherBankVO build = OtherBankVO.builder().bankName(other.getBankName()).bankCode(other.getBankCode()).balance(money).build();
                                bank.clear();
                                bank.add(build);
                            }
                        }
                        otherSum.addAll(bank);
                    }
                }
                depositStatisticsVO.setOthers(otherSum);
            }
        }
        return sumList;
    }

    /**
     * methodType 对应页面展示顺序
     * @param bankCurrentHistoryDTO
     * @param methodType
     * @return
     */
    private List<DepositStatisticsVO> generalList(BankCurrentHistoryDTO bankCurrentHistoryDTO, Integer methodType) {
        int type;
        String date;
        String lastDate;
        String month = bankCurrentHistoryDTO.getMonth();
        String curMonth = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_MONTH);
        if (StringUtil.isBlank(month) || month.equals(curMonth)) {
            date = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATE);
            lastDate = DateUtil.format(DateUtil.minusDays(
                    DateUtil.parse(date.substring(0, 7) + "-01", DateUtil.PATTERN_DATE), 1), DateUtil.PATTERN_DATE);
            type = 1;
        } else {
            date = DateUtil.format(DateUtil.minusDays(DateUtil.plusMonths(
                    DateUtil.parse(month + "-01", DateUtil.PATTERN_DATE), 1), 1), DateUtil.PATTERN_DATE);
            lastDate = DateUtil.format(DateUtil.minusDays(
                    DateUtil.parse(date.substring(0, 7) + "-01", DateUtil.PATTERN_DATE), 1), DateUtil.PATTERN_DATE);
            type = 2;
        }

        // 公司数量统计
        List<DepositStatisticsVO> companyNumberList = new ArrayList<>();
        switch (type) {
            case 1:
                companyNumberList = bankAccountInfoMapper.getCompanyNumberByBank(date,bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
                if (CollectionUtil.isNotEmpty(companyNumberList)){
                    companyNumberList = companyNumberList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
                }
                break;
            case 2:
                companyNumberList = bankCurrentHistoryMapper.getCompanyNumberByBank(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
                if (CollectionUtil.isNotEmpty(companyNumberList)){
                    companyNumberList = companyNumberList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
                }
                break;
            default:
                break;
        }

        // 账户数量统计
        if (methodType == 3 || methodType == 5){
            List<DepositStatisticsVO> accountNumberList = new ArrayList<>();
            switch (type) {
                case 1:
                    accountNumberList = bankAccountInfoMapper.getAccountNumberByBank(date,bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
                    if (CollectionUtil.isNotEmpty(accountNumberList)){
                        accountNumberList = accountNumberList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
                    }
                    break;
                case 2:
                    accountNumberList = bankCurrentHistoryMapper.getAccountNumberByBank(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
                    if (CollectionUtil.isNotEmpty(accountNumberList)){
                        accountNumberList = accountNumberList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
                    }
                    break;
                default:
                    break;
            }

            if (CollectionUtil.isNotEmpty(companyNumberList)) {
                for (DepositStatisticsVO result : companyNumberList) {
                    if (CollectionUtil.isNotEmpty(accountNumberList)) {
                        for (DepositStatisticsVO depositStatisticsVO : accountNumberList) {
                            if (depositStatisticsVO.getTopGroupId().equals(result.getTopGroupId())) {
                                result.setAccountNumber(depositStatisticsVO.getAccountNumber());
                            }
                        }
                    }
                }
            }
        }


        //活期存款统计
        List<DepositStatisticsVO> demandList = new ArrayList<>();
        switch (type) {
            case 1:
                demandList = bankAccountInfoMapper.statisticsByTopIdAndBank(bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
                if (CollectionUtil.isNotEmpty(demandList)){
                    demandList = demandList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
                }
                break;
            case 2:
                demandList = bankCurrentHistoryMapper.statisticsByTopIdAndBank(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
                if (CollectionUtil.isNotEmpty(demandList)){
                    demandList = demandList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
                }
                break;
            default:
                break;
        }

        //定期存款统计
        List<DepositStatisticsVO> list = bankDepositMapper.statisticsByTopIdAndBank(date, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
        if (CollectionUtil.isNotEmpty(list)){
            list = list.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
        }

        //合计
        List<DepositStatisticsVO> depositStatisticsVOS = sumByTopId(demandList, list, companyNumberList);

        //上月合计
        if (methodType == 4 || methodType == 5){
            List<DepositStatisticsVO> lastDemandList = bankCurrentHistoryMapper.statisticsByTopIdAndBank(lastDate, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
            if (CollectionUtil.isNotEmpty(lastDemandList)){
                lastDemandList = lastDemandList.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
            }
            List<DepositStatisticsVO> lastTimeDeposits = bankDepositMapper.statisticsByTopIdAndBank(lastDate, bankCurrentHistoryDTO.getTopGroupIds(), bankCurrentHistoryDTO.getBankCodes());
            if (CollectionUtil.isNotEmpty(lastTimeDeposits)){
                lastTimeDeposits = lastTimeDeposits.stream().filter(m->bankCurrentHistoryDTO.getTopGroupIds().contains(m.getTopGroupId())).collect(Collectors.toList());
            }

            List<DepositStatisticsVO> lastDepositStatisticsVOS = lastSumByTopId(lastDemandList, lastTimeDeposits, companyNumberList);

            //环比
            if (CollectionUtil.isNotEmpty(companyNumberList)) {
                for (DepositStatisticsVO result : companyNumberList) {
                    if (CollectionUtil.isNotEmpty(lastDepositStatisticsVOS)) {
                        for (DepositStatisticsVO lastDepositStatisticsVO : lastDepositStatisticsVOS) {
                            if (lastDepositStatisticsVO.getTopGroupId().equals(result.getTopGroupId())) {
                                result.setMonthOnMonth(BigDecimalUtil.divide(BigDecimalUtil.subtract(result.getBalance(), result.getLastBalance()),
                                        result.getLastBalance(), 2, BigDecimal.ROUND_HALF_UP, 100));
                            }
                        }
                    }
                }
            }
        }


        //活期定期求和
        List<String> topGroupIds = bankCurrentHistoryDTO.getTopGroupIds();
        List<DepositStatisticsVO> depositStatisticsVOListSum = new ArrayList<>();
        for (String topGroupId : topGroupIds) {
            List<DepositStatisticsVO> temporaryList = new ArrayList<>();
            for (DepositStatisticsVO depositStatisticsVO : demandList) {
                if (depositStatisticsVO.getTopGroupId().equals(topGroupId)) {
                    List<OtherBankVO> others = depositStatisticsVO.getOthers();
                    if (CollectionUtil.isNotEmpty(others)) {
                        for (OtherBankVO other : others) {
                            other.setBalance(BigDecimalUtil.divide(other.getBalance(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                        }
                    }
                    temporaryList.add(depositStatisticsVO);
                }
            }
            for (DepositStatisticsVO statisticsVO : list) {
                if (statisticsVO.getTopGroupId().equals(topGroupId)) {
                    List<OtherBankVO> others = statisticsVO.getOthers();
                    if (CollectionUtil.isNotEmpty(others)) {
                        for (OtherBankVO other : others) {
                            other.setBalance(BigDecimalUtil.divide(other.getBalance(), new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP));
                        }
                    }
                    temporaryList.add(statisticsVO);
                }
            }
            if (temporaryList.size() >= 2) {
                List<DepositStatisticsVO> depositStatisticsVOList = sumList(demandList, list);
                depositStatisticsVOListSum.addAll(depositStatisticsVOList);
            } else {
                depositStatisticsVOListSum.addAll(temporaryList);
            }
        }

        if (CollectionUtil.isNotEmpty(companyNumberList)) {
            for (DepositStatisticsVO result : companyNumberList) {
                if (CollectionUtil.isNotEmpty(depositStatisticsVOListSum)) {
                    for (DepositStatisticsVO depositStatisticsVO : depositStatisticsVOListSum) {
                        if (result.getTopGroupId().equals(depositStatisticsVO.getTopGroupId())) {
                            result.setOthers(depositStatisticsVO.getOthers());
                        }
                    }
                }
            }
        }
        return companyNumberList;
    }

//    @Override
//    public Double getDepositBalance(Map<String,Object> map){
//        Double value=bankCurrentHistoryMapper.getDepositBalance(map);
//        return  value;
//    }
//
//    private void getAllSubCompany(FacadeSummaryVO facadeSummaryVO,String month){
//        List<FacadeSummaryVO> subCompany = facadeSummaryVO.getSubCompany();
//        if (CollectionUtil.isNotEmpty(subCompany)){
//            for (FacadeSummaryVO facadeSummary:subCompany){
//                OrganzationMonthRatio fOrgMonthRatio=new OrganzationMonthRatio();
//                fOrgMonthRatio.setOrgCode(facadeSummary.getCompanyCode());
//                fOrgMonthRatio.setMonth(month);
//                fOrgMonthRatio.setFinancingCostRatio(facadeSummary.dailyFinancingCostRateYear.toString());
//                try {
//                    organzationMonthRatioService.edit(fOrgMonthRatio);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//                getAllSubCompany(facadeSummary,month);
//            }
//        }
//    }

//    /**
//     * 市属国有企业银行账户及存贷款汇总
//     * @param pd
//     * @return
//     */
//    @Override
//    public ListResult<PageData> getBankAccountAndDepositLoan(PageData pd){
//        try {
//            String orgId=TokenUtil.getTokenOrgId();
//            String reportTime=pd.getString("reportTime");
//            String lastMonthDate=DateUtil.getThisMonthlastdate(reportTime);
//            PageData param=new PageData();
//            param.put("reportTime", DateUtil.getThisMonthlastdate(reportTime));
//            String issame="0";
//            boolean isSameMonth=DateUtil.isTheSameMonth(reportTime);
//            NumberFormat ddf= NumberFormat.getNumberInstance() ;
//            ddf.setMaximumFractionDigits(2);
//            String dateStr=new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//            if(isSameMonth){
//                issame="1";
//            }else{
//                dateStr=DateUtil.getThisMonthlastdate(reportTime);
//            }
//            ListResult<PageData> resList=new ListResult<>(CommonCode.SUCCESS);
//            List<PageData> list=new ArrayList<>();
//            param.put("isSameMonth",issame);
//            param.put("month",reportTime);
//            param.put("date",dateStr);
//            //存款数据包括fr_bank_account_info或者fr_bank_current_history 加上fr_bank_deposit之和
//            list=bankCurrentHistoryMapper.getBankAccountAndDepositLoan(param);
//            //fr_bank_deposit的存款数据
//            List<BankDepositVO> bankDepositVOS=bankDepositMapper.selectSumBankDepositList(param);
//            Map<String,BigDecimal> bankDepositMap=bankDepositVOS.stream().collect(Collectors.toMap(BankDeposit::getTopGroupId,BankDeposit::getDepositAmount));
//            String gzwOrgId = gzwProperties.getId();
//                int sumCompanyNum = 0;
//                int sumAccountNum = 0;
//                BigDecimal sumBalance = new BigDecimal(0);
//                BigDecimal sumQmye = new BigDecimal(0);
//                int sumZyNum = 0;
//                int sumYcxNum = 0;
//                int sumYbNum = 0;
//                int sumNcxNum = 0;
//                int sumJbNum = 0;
//                int sumLsNum = 0;
//                int sumLcNum = 0;
//
//
//                for(PageData p:list){
//                    double cdb=0.0;
//                    String cdbStr="/";
//                    String balStr=p.getString("balance");
//                    String porgCode=p.getString("orgCode");
//                    String porgId=p.getString("orgId");
//                    BigDecimal balance=new BigDecimal(0);
//                    BigDecimal tempQmye=BigDecimalUtil.toBigdecimal(p.getString("qmye"));
//                    if(balStr!=null){
//                        balance=BigDecimalUtil.toBigdecimal(balStr);
//                        //如何其他存款数据里有数据，则加上这部分
//                        if(bankDepositMap.containsKey(porgId)){
//                            balance=balance.add(bankDepositMap.get(porgId));
//                        }
//                        balance=balance.divide(new BigDecimal(10000)).setScale(2, RoundingMode.HALF_UP);
//                    }
//                    p.put("ncxzx",p.getString("ncxNum")+"/"+p.getString("ycxNum"));
//                    p.put("qmye",tempQmye.setScale(2, RoundingMode.HALF_UP).toString());
//                    p.put("balance",balance.toString());
//
//                    if(tempQmye.compareTo(new BigDecimal(0))==0){
//                        p.put("cdb","/");
//                    }else{
//                        BigDecimal tempCdb=BigDecimalUtil.divide(BigDecimalUtil.toBigdecimal(p.getString("balance")), tempQmye, 2, BigDecimal.ROUND_HALF_UP, 100);
//                        p.put("cdb", tempCdb==null?"0.00":tempCdb.toString());
//                    }
//                    sumCompanyNum += p.getInteger("companyNum");
//                    sumAccountNum += p.getInteger("accountNum");
//                    sumBalance = BigDecimalUtil.add(sumBalance, BigDecimalUtil.toBigdecimal(p.getString("balance")));
//                    sumQmye = BigDecimalUtil.add(sumQmye, BigDecimalUtil.toBigdecimal(p.getString("qmye")));
//
//                    sumZyNum += p.getInteger("zyNum");
//                    sumYcxNum += p.getInteger("ycxNum");
//                    sumYbNum += p.getInteger("ybNum");
//                    sumNcxNum += p.getInteger("ncxNum");
//                    sumJbNum += p.getInteger("jbNum");
//                    sumLsNum += p.getInteger("lsNum");
//                    sumLcNum += p.getInteger("lcNum");
//                }
//
//                Iterator<PageData> it = list.iterator();
//                //报表中增加广电合并节点，将宁波广播电视集团和宁波广电传媒集团有限公司各自数据汇总
//                PageData gdPageData=new PageData();
//                gdPageData.put("accountNum",0);
//                gdPageData.put("companyNum",0);
//                gdPageData.put("jbNum",0);
//                gdPageData.put("lsNum",0);
//                gdPageData.put("ncxNum",0);
//                gdPageData.put("ybNum",0);
//                gdPageData.put("ycxNum",0);
//                gdPageData.put("zyNum", 0);
//                gdPageData.put("lcNum", 0);
//                gdPageData.put("balance", 0);
//                gdPageData.put("companyName", "宁波广电集团合并");
//                gdPageData.put("orgCode", "00010106");
//                gdPageData.put("orgId", "d00a8c0192d6ff2004f6b56edf747244");
//                PageData gdParam=new PageData();
//                gdParam.put("month",reportTime);
//                gdParam.put("orgCode","00010106");
//                OrganzationMonthRatio gdOrm=organzationMonthRatioService.findByMonthAndOrgcode(gdParam);
//                gdPageData.put("qmye",gdOrm.getLoan());
//                int index=0;
//                int i=0;
//                while(it.hasNext()){
//                    PageData p=it.next();
//                    String porgId=p.getString("orgId");
//                    if(porgId!=null&&(porgId.equals("1a8c455396d7df8c96a53cb60de8c91a")||porgId.equals("59a802b15088e97a57de07a43593fe5e"))){
//                        if(porgId.equals("1a8c455396d7df8c96a53cb60de8c91a")){
//                            index=i;
//                        }
//                        gdPageData.put("accountNum",gdPageData.getInteger("accountNum")+p.getInteger("accountNum"));
//                        gdPageData.put("companyNum",gdPageData.getInteger("companyNum")+p.getInteger("companyNum"));
//                        gdPageData.put("jbNum",gdPageData.getInteger("jbNum")+p.getInteger("jbNum"));
//                        gdPageData.put("lsNum",gdPageData.getInteger("lsNum")+p.getInteger("lsNum"));
//                        gdPageData.put("ncxNum",gdPageData.getInteger("ncxNum")+p.getInteger("ncxNum"));
//                        gdPageData.put("ybNum",gdPageData.getInteger("ybNum")+p.getInteger("ybNum"));
//                        gdPageData.put("ycxNum",gdPageData.getInteger("ycxNum")+p.getInteger("ycxNum"));
//                        gdPageData.put("zyNum",gdPageData.getInteger("zyNum")+p.getInteger("zyNum"));
//                        gdPageData.put("lcNum",gdPageData.getInteger("lcNum")+p.getInteger("lcNum"));
//                        gdPageData.put("balance",BigDecimalUtil.toBigdecimal(gdPageData.getString("balance")).add(BigDecimalUtil.toBigdecimal(p.getString("balance"))));
//                        it.remove();
//                    }
//                    i++;
//                }
//                BigDecimal gdhbCdb=BigDecimalUtil.divide(BigDecimalUtil.toBigdecimal(gdPageData.getString("balance")),BigDecimalUtil.toBigdecimal(gdOrm.getLoan()), 2, BigDecimal.ROUND_HALF_UP, 100);
//                gdPageData.put("cdb",gdhbCdb==null?"0.00":gdhbCdb.toString());
//                gdPageData.put("ncxzx",gdPageData.getString("ncxNum")+"/"+gdPageData.getString("ycxNum"));
//                list.add(index,gdPageData);
//
//                if(orgId.equals(gzwOrgId)) {
//                    PageData sumPd = new PageData();
//                    sumPd.put("companyName", "总计");
//                    sumPd.put("companyNum", sumCompanyNum);
//                    sumPd.put("accountNum", sumAccountNum);
//                    sumPd.put("balance", BigDecimalUtil.toShortString(sumBalance, 2));
//                    sumPd.put("qmye", new BigDecimal(String.valueOf(sumQmye)).setScale(2, RoundingMode.HALF_UP));
//                    sumPd.put("zyNum", sumZyNum);
//                    sumPd.put("ycxNum", sumYcxNum);
//                    sumPd.put("ybNum", sumYbNum);
//                    sumPd.put("ncxNum", sumNcxNum);
//                    sumPd.put("jbNum", sumJbNum);
//                    sumPd.put("lsNum", sumLsNum);
//                    sumPd.put("lcNum", sumLcNum);
//                    sumPd.put("ncxzx", sumNcxNum + "/" + sumYcxNum);
//                    BigDecimal tempSumCdb=BigDecimalUtil.divide(sumBalance, sumQmye, 2, BigDecimal.ROUND_HALF_UP, 100);
//                    sumPd.put("cdb",tempSumCdb==null?"0.00":tempSumCdb.toString());
//                    list.add(sumPd);
//                }else{
//                    list=list.stream().filter(record->record.getString("orgId").equals(orgId)).collect(Collectors.toList());
//                }
//                resList.setList(list);
//                resList.setTotal(list.size());
//                return resList;
//        }catch (Exception e){
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return new ListResult<>(CommonCode.ERROR);
//        }
//    }
//
//    public void getBankAccountDepositLoan(BankReportDTO dto){
//        List<BankAccountDepositLoanVO> bankAccountDepositLoanVOS = new ArrayList<>();
//
//        String reportTime = dto.getReportTime();
//        Date date = DateUtil.plusMonths(DateUtil.parse(reportTime, DateUtil.PATTERN_MONTH), 1);
//        //获取13家企业
//        List<Org> orgList = orgService.directlyUnderUnit();
//        //全部组织/产权
//        List<Org> allOrg = orgService.getAllOrg();
//        List<PropertyBasics> allProperty = propertyBasicsService.list();
//
//        //宁波银行视图：账户
//        List<ReportAccInfo> reportAccInfos = accInfoService.getAccInfos(date);
//        // 存款
//        List<ReportBalance> reportBalances = balanceService.getBalances(date);
//        //金蝶每日保存：贷款
//        List<OrganzationMonthRatio> monthRatios = monthRatioMapper.selectList(Wrappers.<OrganzationMonthRatio>lambdaQuery().eq(OrganzationMonthRatio::getMonth, reportTime));
//        int a = 0;
//        for (Org org:orgList){
//            BankAccountDepositLoanVO resultVO = new BankAccountDepositLoanVO();
//            resultVO.setIndexNum(String.valueOf(a++));
//            resultVO.setOrgName(org.getName());
//
//            String orgCode = org.getOrgCode();
//            List<Org> childOrgs = allOrg.stream().filter(m -> Optional.ofNullable(m.getOrgCode()).isPresent() && m.getOrgCode().length() >= orgCode.length() && m.getOrgCode().startsWith(orgCode))
//                    .collect(Collectors.toList());
//            if (CollectionUtil.isNotEmpty(childOrgs)){
//                resultVO.setOrgQuantity(childOrgs.size());
//            }else {
//                resultVO.setOrgQuantity(0);
//            }
//            PropertyBasics basics = allProperty.stream().filter(m -> Optional.ofNullable(m.getOrgId()).isPresent() && org.getId().equals(m.getOrgId())).findFirst().get();
//            String aicOrgCode = basics.getAicOrgCode();
//
//            if (CollectionUtil.isNotEmpty(reportAccInfos)){
//                List<ReportAccInfo> accInfos = reportAccInfos.stream().filter(m -> Optional.ofNullable(m.getGroupCode()).isPresent() && aicOrgCode.equals(m.getGroupCode())).collect(Collectors.toList());
//                if (CollectionUtil.isNotEmpty(accInfos)){
//                    resultVO.setAccountQuantity(accInfos.size());
//                }
//            }
//
//        }
//
//
//
//
//    }
//
//    /**
//     * 企业银行存款借款汇总
//     * @param pd
//     * @return
//     */
//    @Override
//    public R<PageData> getSummarydepositsloans(PageData pd){
//        try{
//            R<PageData> rResult=new R<>(CommonCode.SUCCESS);
//            PageData presult=new PageData();
//            String orgId = pd.getString("orgId");
//            String reportTime=pd.getString("reportTime");
//            String issame="0";
//            boolean isSameMonth=DateUtil.isTheSameMonth(reportTime);
//            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//            String nowDateStr=DateUtil.getThisMonthlastdate(reportTime);
//            if(isSameMonth){
//                issame="1";
//                nowDateStr=sdf.format(new Date());
//            }
//            pd.put("date",nowDateStr);
//            pd.put("isSameMonth",issame);
//            pd.put("topGroupId",pd.getString("orgId"));
//            PageData nowPd=bankCurrentHistoryMapper.selectAllBankDeposit(pd);
//            pd.put("isSameMonth","0");
//            pd.put("date",DateUtil.getLastMonthlastdate(reportTime));
//            pd.put("reportTime", DateUtil.getThisMonthlastdate(reportTime));
//            PageData prePd=bankCurrentHistoryMapper.selectAllBankDeposit(pd);
//            BigDecimal nowqmye=new BigDecimal(0);//这个月融资余额
//            BigDecimal preqmye=new BigDecimal(0);//上个月融资余额
//            //这个月存款余额
//            BigDecimal nowbalance=nowPd==null?new BigDecimal(0):BigDecimalUtil.toBigdecimal(nowPd.getString("balance"));
//            //上个月存款余额
//            BigDecimal prebalance=prePd==null?new BigDecimal(0):BigDecimalUtil.toBigdecimal(prePd.getString("balance"));
//            NumberFormat ddf= NumberFormat.getNumberInstance() ;
//            ddf.setMaximumFractionDigits(2);
//            String orgName="";
//            String lastMonth=DateUtil.getLastMonth(reportTime);
//            PageData pId = new PageData();
//            pId.put("id",orgId);
//            PageData orgPd=orgzationDao.findbyid(orgId);
//            String orgCode=orgPd.get("orgCode").toString();
//            orgName=orgPd.getString("orgName");
//            PageData qpd=new PageData();
//            qpd.put("month",lastMonth);
//            qpd.put("orgCode",orgCode);
//            OrganzationMonthRatio lastOrgMonthRatio=organzationMonthRatioService.findByMonthAndOrgcode(qpd);
//            if(lastOrgMonthRatio==null){
//                return rResult;
//            }
//            preqmye=new BigDecimal(lastOrgMonthRatio.getLoan()==null?"0":lastOrgMonthRatio.getLoan());
//            qpd.put("month",reportTime);
//            OrganzationMonthRatio nowOrgMonthRatio=organzationMonthRatioService.findByMonthAndOrgcode(qpd);
//            nowqmye=new BigDecimal(nowOrgMonthRatio.getLoan()==null?"0":nowOrgMonthRatio.getLoan());
//
//            presult.put("companyName",orgName);
//            presult.put("preBalance",prebalance.setScale(2, RoundingMode.HALF_UP).toString());
//            presult.put("nowBalance",nowbalance.setScale(2, RoundingMode.HALF_UP).toString());
//            presult.put("preQmye",preqmye.setScale(2, RoundingMode.HALF_UP).toString());
//            presult.put("nowQmye",nowqmye.setScale(2, RoundingMode.HALF_UP).toString());
//            BigDecimal balanceRatio=new BigDecimal(0);
//            String balanceRatioStr="/";
//            if(!BigDecimalUtil.isZero(prebalance)){
//                balanceRatio=nowbalance.divide(prebalance,2, RoundingMode.HALF_UP).subtract(new BigDecimal(1));
//                balanceRatioStr=balanceRatio.toPlainString();
//            }
//            BigDecimal qmyeRatio=new BigDecimal(0);
//            String qmyeRatioStr="/";
//            if(!BigDecimalUtil.isZero(preqmye)){
//                qmyeRatio=nowqmye.divide(preqmye,2, RoundingMode.HALF_UP).subtract(new BigDecimal(1));
//                qmyeRatioStr=qmyeRatio.toPlainString();
//            }
//            presult.put("balanceRatio",balanceRatioStr);
//            presult.put("qmyeRatio",qmyeRatioStr);
//            String cdbStr="/";
//            if(!BigDecimalUtil.isZero(nowqmye)){
//                BigDecimal cdb=nowbalance.multiply(new BigDecimal(100)).divide(nowqmye,2, RoundingMode.HALF_UP);
//                cdbStr=cdb.toPlainString();
//            }
//            presult.put("cdb",cdbStr);
//            rResult.setPageData(presult);
//            return  rResult;
//        }catch (Exception e){
//            log.error(ExceptionUtils.getFullStackTrace(e));
//            return new R<>(CommonCode.ERROR);
//        }
//    }
//
//    /**
//     * 返回银行资金企业汇总信息
//     * @param pd
//     * @return
//     */
//
//    @Override TODO DEL
//    public ListResult<PageData> getCompanySummary(PageData pd){
//        try{
//            ListResult<PageData> resList=new ListResult<>(CommonCode.SUCCESS);
//            String reportTime=pd.getString("reportTime");
//            String issame="0";
//            boolean isSameMonth=DateUtil.isTheSameMonth(reportTime);
//            String date=DateUtil.getLastMonthlastdate(reportTime);
//            if(isSameMonth){
//                issame="1";
//                SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//                date=sdf.format(new Date());
//            }
//            pd.put("month",reportTime);
//            pd.put("date",date);
//            pd.put("isSameMonth",issame);
//            pd.put("reportTime",DateUtil.getLastMonthlastdate(reportTime));
//            pd.put("topGroupId",pd.getString("orgId"));
//            List<PageData> list=bankCurrentHistoryMapper.getCompanySummary(pd);
//            List<OrganzationMonthRatio> loanInfoList=organzationMonthRatioService.getInfoByPorgId(pd);
//            List<String> orgNames=new ArrayList<>();
//            Map<String,String> loanMap=new HashMap<>();
//            if(CollectionUtil.isNotEmpty(loanInfoList)){
//                loanMap=loanInfoList.stream().collect(Collectors.toMap(record->record.getOrgName(),record->record.getLoan()));
//            }
//            PageData sumPd=new PageData();
//            sumPd.put("orgName","总计");
//            BigDecimal sumLoan=new BigDecimal(0);
//            BigDecimal sumDeposit=new BigDecimal(0);
//            int sumAccountnum=0;
//            for(PageData p:list){
//                String orgName=p.getString("orgName");
//                if(loanMap.containsKey(orgName)){
//                    p.put("loan",loanMap.get(orgName));
//                    orgNames.add(orgName);
//                }else{
//                    p.put("loan","0.00");
//                }
//                sumAccountnum+=Integer.parseInt(p.getString("accountnum"));
//                BigDecimal loan=BigDecimalUtil.toBigdecimal(p.getString("loan")).setScale(2, RoundingMode.HALF_UP);
//                BigDecimal deposit=BigDecimalUtil.toBigdecimal(p.getString("deposit")).setScale(2, RoundingMode.HALF_UP);
//                sumLoan=sumLoan.add(BigDecimalUtil.toBigdecimal(p.getString("loan")));
//                sumDeposit=sumDeposit.add(BigDecimalUtil.toBigdecimal(p.getString("deposit")));
//                p.put("loan",loan.toString());
//                p.put("deposit",deposit.toString());
//                if(loan.compareTo(new BigDecimal(0))==0){
//                    p.put("loan_deposit_ratio","/");
//                }else{
//                    BigDecimal loan_deposit_ratio=deposit.multiply(new BigDecimal(100)).divide(loan,2, RoundingMode.HALF_UP);
//                    p.put("loan_deposit_ratio",loan_deposit_ratio.toString());
//                }
//            }
//            for(OrganzationMonthRatio r:loanInfoList){
//                String orgName=r.getOrgName();
//                //不和存款账号单位对的上的贷款数据额外加上
//                if(!orgNames.contains(orgName)){
//                    PageData p=new PageData();
//                    p.put("orgName",orgName);
//                    p.put("loan",r.getLoan());
//                    p.put("deposit","0.00");
//                    BigDecimal loan=BigDecimalUtil.toBigdecimal(p.getString("loan")).setScale(2, RoundingMode.HALF_UP);
//                    sumLoan=sumLoan.add(BigDecimalUtil.toBigdecimal(p.getString("loan")));
//                    if(loan.compareTo(new BigDecimal(0))==0){
//                        p.put("loan_deposit_ratio","/");
//                    }else{
//                        p.put("loan_deposit_ratio","0.00");
//                    }
//                    p.put("accountnum",0);
//                    list.add(p);
//                }
//            }
//            if(list.size()>0){
//                sumPd.put("loan",sumLoan.setScale(2, RoundingMode.HALF_UP).toString());
//                sumPd.put("deposit",sumDeposit.setScale(2, RoundingMode.HALF_UP).toString());
//                sumPd.put("accountnum",sumAccountnum);
//                if(sumLoan.compareTo(new BigDecimal(0))==0){
//                    sumPd.put("loan_deposit_ratio","/");
//                }else{
//                    sumPd.put("loan_deposit_ratio",sumDeposit.multiply(new BigDecimal(100)).divide(sumLoan,2, RoundingMode.HALF_UP));
//                }
//                list.add(sumPd);
//            }
//            resList.setList(list);
//            resList.setTotal(list.size());
//            return resList;
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        return null;
//    }
}
